package net;

import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;

public class Demo1 {
	public static void main(String[] args) throws IOException {
		InetAddress host = InetAddress.getLocalHost();
		System.out.println(host);
		
		InetAddress baidu = InetAddress.getByName("www.baidu.com");
		System.out.println(baidu);
		
		boolean bool = baidu.isReachable(5000);
		System.out.println(bool);
		
		
		URL url = new URL("http://www.hyycinfo.com/index.html");
		System.out.println(url.getProtocol());
		System.out.println(url.getHost());
		System.out.println(url.getPath());
		//
		URLConnection conn = url.openConnection();
		
		InputStream in = conn.getInputStream();
		
//		byte[] bytes = new byte[100];
//		int count;
//		while( ( count = in.read(bytes) ) > -1 ) {
//			String s = new String(bytes,0,count,"UTF-8");
//			System.out.println(s);
//		}
		try(
				InputStreamReader isr = new InputStreamReader(in,"utf-8");
				BufferedReader br = new BufferedReader(isr);
				FileWriter fw = new FileWriter("D:\\eclipse-jee-2020-12-R-win32-x86_64\\html");){
			String line;
			while( ( line = br.readLine() ) != null ) {
				System.out.println(line);
				line+="\r\n";
				fw.write(line,0,line.length());
			}
		}
		in.close();
		
	}
	
	
}
